﻿using System.Collections.Generic;
using BoutiquePOS.DAL.DAO;
using BoutiquePOS.DAL.Gateway;


namespace BoutiquePOS.Manager
{
    public class SupplierManager
    {
        SupplierGateway supplierGateway = new SupplierGateway();
      
        public Supplier FindSupplier(string supplierName)
        {
            return new SupplierGateway().FindSupplier(supplierName);
        }

        //for supplier save
        public string SaveSupplier(Supplier aSupplier)
        {
            if (!DoesThisSupplierExist(aSupplier))
                return supplierGateway.SaveSupplierGateway(aSupplier);
            else
            {
                return "This Supplier Info Already Exists";
            }
        }

        private bool DoesThisSupplierExist(Supplier supplier)
        {
            List<Supplier> suppliers = new List<Supplier>();
            suppliers = supplierGateway.GetAllSupplier();

            foreach (Supplier supplierObj in suppliers)
            {
                if (supplierObj.SupplierName == supplier.SupplierName)
                    return true;
            }
            return false;
        }

        public string DeleteSupplier(int supplierId)
        {
            string message= supplierGateway.DeleteSupplierById(supplierId);
            return message;  
        }
        public List<Supplier> GetAllSupplierByIdOrName(int i, string Id)
        {
            return supplierGateway.GetAllSupplierByCodeOrName(i, Id);
        }

        public List<Supplier> GetAllSupplier()
        {
            return supplierGateway.GetAllSupplier();
        }
        public string GetallSupplierName()
        {
            return supplierGateway.GetAllSupplierName();
        }       
    }
}